package com.sun.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * 学习@RequestMapping注解的使用
 * 学习如何获取请求参数
 */
@Controller
public class HelloController {

    //@RequestMapping(value = {"/","/index","/index.html"})
    //public String index(){
    //    // 设置视图名称
    //    return "index";
    //}

    @RequestMapping(value = "/test_view")
    public String testView(){
        return "test_view";
    }

    @RequestMapping(value = "/target",method = {RequestMethod.GET,RequestMethod.POST})
    public String toTarget(){
        return "target";
    }

    @RequestMapping(value = "/testPut",method = RequestMethod.PUT)
    public String testPut(HttpServletRequest request){
        System.out.println("request.getMethod() = " + request.getMethod());
        return "target";
    }

    @RequestMapping(value = "/testRequestParam",
            method = RequestMethod.GET,
            params = {"userName","!age","sex=0"},headers = {"Host=localhost:8081"})
    public String testRequestParam(){
        return "target";
    }


}
